//
//  ZLPullMenuItem.swift
//  ZLPullMenuSwift
//
//  Created by 科大 on 2025/1/16.
//

import UIKit

public class ZLPullMenuOption {
    /// 选项标题
    public var optionTitle: String
    
    /// 样式配置
    public var config: ZLPullMenuOptionConfig
    
    /// 是否选中
    public var selected: Bool
    
    /// 初始化
    public init(optionTitle: String, selected: Bool, config: ZLPullMenuOptionConfig = ZLPullMenuOptionConfig.defaultConfig() as! ZLPullMenuOptionConfig) {
        self.optionTitle = optionTitle
        self.selected = selected
        self.config = config
    }
    
    /// 便利构造方法
    public class func option(title: String, selected: Bool) -> ZLPullMenuOption {
        return ZLPullMenuOption(optionTitle: title, selected: selected)
    }
    
    public class func option(title: String, selected: Bool, config: ZLPullMenuOptionConfig) -> ZLPullMenuOption {
        return ZLPullMenuOption(optionTitle: title, selected: selected, config: config)
    }
}

// MARK: - ZLPullMenuGroup

public class ZLPullMenuGroup {
    /// 组标题
    public var groupTitle: String
    
    /// 样式配置
    public var config: ZLPullMenuGroupConfig
    
    /// 是否多选
    public var selecteds: Bool
    
    /// 是否必选
    public var mustSelect: Bool
    
    /// 选项列表
    public var options: [ZLPullMenuOption]
    
    /// 初始化
    public init(groupTitle: String,
                selecteds: Bool = false,
                mustSelect: Bool = false,
                options: [ZLPullMenuOption],
                config: ZLPullMenuGroupConfig = ZLPullMenuGroupConfig.defaultConfig() as! ZLPullMenuGroupConfig) {
        self.groupTitle = groupTitle
        self.selecteds = selecteds
        self.mustSelect = mustSelect
        self.options = options
        self.config = config
    }
    
    /// 便利构造方法
    public class func group(title: String, options: [ZLPullMenuOption]) -> ZLPullMenuGroup {
        return ZLPullMenuGroup(groupTitle: title, options: options)
    }
    
    public class func group(title: String,
                            selecteds: Bool,
                            mustSelect: Bool,
                            options: [ZLPullMenuOption]) -> ZLPullMenuGroup {
        return ZLPullMenuGroup(groupTitle: title,
                               selecteds: selecteds,
                               mustSelect: mustSelect,
                               options: options)
    }
    
    public class func group(title: String,
                            selecteds: Bool,
                            mustSelect: Bool,
                            options: [ZLPullMenuOption],
                            config: ZLPullMenuGroupConfig) -> ZLPullMenuGroup {
        return ZLPullMenuGroup(groupTitle: title,
                               selecteds: selecteds,
                               mustSelect: mustSelect,
                               options: options,
                               config: config)
    }
    
    public func selectedOptions() -> [ZLPullMenuOption] {
        return self.options.filter { $0.selected == true }
    }
}

// MARK: - ZLPullMenuItem

public class ZLPullMenuItem {
    /// 顶部菜单标题
    public var menuTitle: String
    
    /// 样式配置
    public var config: ZLPullMenuConfig
    
    /// 分组列表
    public var groups: [ZLPullMenuGroup]
    
    /// 是否选中
    public var selected: Bool
    
    /// 初始化
    public init(menuTitle: String,
                groups: [ZLPullMenuGroup],
                config: ZLPullMenuConfig = ZLPullMenuConfig.defaultConfig() as! ZLPullMenuConfig,
                selected: Bool = false) {
        self.menuTitle = menuTitle
        self.groups = groups
        self.config = config
        self.selected = selected
    }
    
    /// 便利构造方法
    public class func item(title: String, groups: [ZLPullMenuGroup]) -> ZLPullMenuItem {
        return ZLPullMenuItem(menuTitle: title, groups: groups)
    }
    
    public class func item(title: String,
                           groups: [ZLPullMenuGroup],
                           config: ZLPullMenuConfig) -> ZLPullMenuItem {
        return ZLPullMenuItem(menuTitle: title, groups: groups, config: config)
    }
}
